package net.lab1024.sa.admin.module.business.erp.service;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.lab1024.sa.admin.module.business.erp.dao.AccountcDao;
import net.lab1024.sa.admin.module.business.erp.domain.entity.AccountcEntity;
import net.lab1024.sa.admin.module.business.erp.domain.form.add.AccountcAddForm;
import net.lab1024.sa.admin.module.business.erp.domain.form.query.AccountcQueryForm;
import net.lab1024.sa.admin.module.business.erp.domain.form.update.AccountcUpdateForm;
import net.lab1024.sa.admin.module.business.erp.domain.vo.AccountcVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 生产订单与用户关系表 Service
 *
 * @Author akita
 * @Date 2025-04-19 13:19:25
 * @Copyright akita
 */

@Service
public class AccountcService {

    @Resource
    private AccountcDao accountcDao;

    /**
     * 分页查询
     */
    public PageResult<AccountcVO> queryPage(AccountcQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<AccountcVO> list = accountcDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(AccountcAddForm addForm) {
        AccountcEntity accountcEntity = SmartBeanUtil.copy(addForm, AccountcEntity.class);
        accountcDao.insert(accountcEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(AccountcUpdateForm updateForm) {
        AccountcEntity accountcEntity = SmartBeanUtil.copy(updateForm, AccountcEntity.class);
        accountcDao.update(accountcEntity,new LambdaQueryWrapper<AccountcEntity>().eq(AccountcEntity::getDocEntry,updateForm.getDocEntry()).eq(AccountcEntity::getLineNum,updateForm.getLineNum()));
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        accountcDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long docEntry) {
        if (null == docEntry){
            return ResponseDTO.ok();
        }

        accountcDao.deleteById(docEntry);
        return ResponseDTO.ok();
    }
}
